package com.ruoyi.system.service.impl;

import java.util.ArrayList;
import java.util.List;
import java.util.stream.Collectors;

import com.ruoyi.common.core.domain.Ztree;
import com.ruoyi.common.utils.StringUtils;
import org.apache.commons.collections4.CollectionUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.ruoyi.system.mapper.TFrontMenuMapper;
import com.ruoyi.system.domain.TFrontMenu;
import com.ruoyi.system.service.ITFrontMenuService;
import com.ruoyi.common.core.text.Convert;

/**
 * 前端菜单Service业务层处理
 * 
 * @author kellen
 * @date 2024-04-17
 */
@Service
public class TFrontMenuServiceImpl implements ITFrontMenuService 
{
    @Autowired
    private TFrontMenuMapper tFrontMenuMapper;

    /**
     * 查询前端菜单
     * 
     * @param id 前端菜单主键
     * @return 前端菜单
     */
    @Override
    public TFrontMenu selectTFrontMenuById(Long id)
    {
        return tFrontMenuMapper.selectTFrontMenuById(id);
    }

    /**
     * 查询前端菜单列表
     * 
     * @param tFrontMenu 前端菜单
     * @return 前端菜单
     */
    @Override
    public List<TFrontMenu> selectTFrontMenuList(TFrontMenu tFrontMenu)
    {
        return tFrontMenuMapper.selectTFrontMenuList(tFrontMenu);
    }

    /**
     * 新增前端菜单
     * 
     * @param tFrontMenu 前端菜单
     * @return 结果
     */
    @Override
    public int insertTFrontMenu(TFrontMenu tFrontMenu)
    {
        return tFrontMenuMapper.insertTFrontMenu(tFrontMenu);
    }

    /**
     * 修改前端菜单
     * 
     * @param tFrontMenu 前端菜单
     * @return 结果
     */
    @Override
    public int updateTFrontMenu(TFrontMenu tFrontMenu)
    {
        return tFrontMenuMapper.updateTFrontMenu(tFrontMenu);
    }

    /**
     * 批量删除前端菜单
     * 
     * @param ids 需要删除的前端菜单主键
     * @return 结果
     */
    @Override
    public int deleteTFrontMenuByIds(String ids)
    {
        return tFrontMenuMapper.deleteTFrontMenuByIds(Convert.toStrArray(ids));
    }

    /**
     * 删除前端菜单信息
     * 
     * @param id 前端菜单主键
     * @return 结果
     */
    @Override
    public int deleteTFrontMenuById(Long id)
    {
        return tFrontMenuMapper.deleteTFrontMenuById(id);
    }

    @Override
    public List<Ztree> queryMenuTree() {
        TFrontMenu condition = new TFrontMenu();
        condition.setIsDisplay(1L);
        List<TFrontMenu> tFrontMenus = this.tFrontMenuMapper.selectTFrontMenuList(condition);
        List<Ztree> menus = new ArrayList<>();
        if (CollectionUtils.isNotEmpty(tFrontMenus)) {
            for (TFrontMenu tFrontMenu : tFrontMenus) {
                Ztree t = new Ztree();
                t.setId(tFrontMenu.getId());
                t.setpId(tFrontMenu.getParentId());
                t.setTitle(tFrontMenu.getMenuName());
                t.setName(tFrontMenu.getMenuName());
                menus.add(t);
            }
        }
        return menus;
    }
}
